package com.project.weimi.adapter;

import java.util.List;

import com.project.weimi.R;
import com.project.weimi.entity.response.CircleEntity;
import com.project.weimi.view.RoundImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CircleAdapter extends BaseAdapter{

	private Context context;
	private List<CircleEntity> circleList;
	
	public CircleAdapter(Context context, List<CircleEntity> circleList) {
		super();
		this.context = context;
		this.circleList = circleList;
	}

	@Override
	public int getCount() {
		return circleList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if(convertView == null){
			vh = new ViewHolder();
			// 解析布局文件
			convertView = LayoutInflater.from(context).inflate(R.layout.circle_listview_item, null);
			vh.img_circle = (RoundImageView)convertView.findViewById(R.id.img_circle);
			vh.tv_title = (TextView)convertView.findViewById(R.id.tv_title);
			vh.tv_date = (TextView)convertView.findViewById(R.id.tv_date);
			vh.tv_content = (TextView)convertView.findViewById(R.id.tv_content);
			convertView.setTag(vh);
		}else{
			vh = (ViewHolder) convertView.getTag();
		}
		
		vh.img_circle.setImageResource(circleList.get(position).getCircleImg());
		vh.tv_title.setText(circleList.get(position).getTitle());
		vh.tv_date.setText(circleList.get(position).getDate());
		vh.tv_content.setText(circleList.get(position).getContent());
		
		return convertView;
	}

	class ViewHolder{
		RoundImageView img_circle;
		TextView tv_title;
		TextView tv_date;
		TextView tv_content;
	}
	
}
